package edu.yourl.presenter;

import edu.yourl.domain.User;
import edu.yourl.domain.exception.NoRegisteredUserException;
import edu.yourl.persistence.IUserRepository;
import edu.yourl.web.ISignInPage;

public class SignInPresenter implements ISignInPresenter {

	private IUserRepository repository;
	
	@Override
	public void doSignIn(ISignInPage page) {
		final String nickname = page.getUser();
		final String password = page.getPassword();
		
		User user = this.repository.getUser(nickname);
		
		if (user != null && user.checkPassword(password)) {
			page.getSession().setUser(user);
		} else {
			throw new NoRegisteredUserException();
		}
	}

	public void setRepository(IUserRepository repository) {
		this.repository = repository;
	}

}
